<?php

class Mnt_ErrorController extends Zend_Controller_Action
{
    public function init()
    {
        $this->_helper->layout->setLayout('browse');
    }
    
    public function forbiddenAction()
    {
        $this->getResponse()->setHttpResponseCode(403);
    }
    
    public function notfoundAction()
    {
        $this->getResponse()->setHttpResponseCode(404);
    }
    
    public function clewboxAction()
    {
        $this->view->message = $this->_getParam('message');
    }

    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');
        
        switch ($errors->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
                // 404 error -- controller or action not found
                $this->getResponse()->setHttpResponseCode(404);
                $this->view->message = 'Route not found';
                break;
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
                // 404 error -- controller or action not found
                $this->getResponse()->setHttpResponseCode(404);
                $this->view->message = 'Controller not found';
                break;
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
        
                // 404 error -- controller or action not found
                $this->getResponse()->setHttpResponseCode(404);
                $this->view->message = 'Action not found';
                break;
            default:
                // application error
                $this->getResponse()->setHttpResponseCode(500);
                $this->view->message = 'Application error';
                
                // conditionally display exceptions
				if ($this->getInvokeArg('displayExceptions') == true) {
					$this->view->exception = $errors->exception;
				} else {
                    // Log exception, if logger available
                    $bootstrap = $this->getInvokeArg('bootstrap');
                    if ($bootstrap->hasPluginResource('Log')) {
                        $log = $bootstrap->getResource('Log');
                        $log->crit($this->view->message, $errors->exception);
                    }
                }
                break;
        }
        
        $this->view->request   = $errors->request;
        $this->_helper->layout->setLayout('browse');
    }
}